import logging
import random

from fastapi import HTTPException

from FQV2.dialogue_management import qwen_intent_recognition
from utils.Config import AppConfig

config = AppConfig()

def qwen_intent_recognition_demo():
    # Your code here
    # 意图识别和对话管理
    conversation_history = []
    text = ["你好，你是谁？",'你叫什么名字','你喜欢什么颜色','你喜欢什么电影']
    for i in range(10):
        conversation_history = qwen_intent_recognition(text[i%4], conversation_history, config)
        print(f"第{i+1}轮历史对话内容: {conversation_history}")
        response_text = conversation_history[-1]['content']
        # print(f"第{i+1}轮回复内容: {response_text}")
        # 休息一下
        import time
        time.sleep(1)

    if not response_text:
        raise HTTPException(status_code=400, detail="意图识别或对话管理失败，未获取到有效回复内容")
    logging.info(f"意图识别和对话管理成功，回复内容: {response_text}")


if __name__ == '__main__':
    qwen_intent_recognition_demo()